#include "compile.hpp"
#include "runner.hpp"
#include "integrate.hpp"
#include "../httplib/cpp-httplib-v0.7.15/httplib.h"

using namespace integrate_cr;
using namespace httplib;

int main(int argc, char* argv[])
{

    int port = atoi(argv[1]);
    Server svr;

    svr.Post("/compile_run", [](const Request& req, Response& resp){
        string in_json = req.body;
        string out_json;

        integrate::Start(in_json, out_json);
        resp.set_content(out_json, "application/json; charset=utf-8");
    });

    svr.listen("0.0.0.0", port);

    // svr.Get("/hello", [](const Request& req, Response& resp){
    //     resp.set_content("hello world", "text/plain; charset=utf-8");
    // });

    // svr.listen("0.0.0.0", port);

    // std::string in_json;
    // Json::Value in_value;
    // //R"()", raw string
    // in_value["code"] = R"(#include<iostream>
    // int main(){
    //     std::cout << "你可以看见我了" << std::endl;
        
    //     return 0;
    // })";
    // in_value["input"] = "";
    // in_value["cpu_limit"] = 1;
    // in_value["mem_limit"] = 10240*100;
    // Json::FastWriter writer;
    // in_json = writer.write(in_value);
    // std::cout << in_json << std::endl;
    // //这个是将来给客户端返回的json串
    // std::string out_json;
    // integrate::Start(in_json, out_json);

    // std::cout << out_json << std::endl;

    return 0;
}